<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">修改组织</h4>
        </div>
        <form style="margin:4%;" id="modalForm">
            <input type="hidden" value="{$orgInfo.id}" name="orgId" />
            <div class="form-group">
                <label for="recipient-name" class="control-label">机构名称:</label>
                <input type="text" class="form-control" name="name" value="{$orgInfo.name}" placeholder="请输入机构名称">
            </div>
            <div class="form-group">
                <label for="recipient-name" class="control-label">上级机构:</label>
                <select name="pid" class="form-control">
                    <option value="">作为顶级机构</option>
                    <foreach name="orgList" item="org">
                        <option value="{$org.id}" <if condition="$org['id'] eq $orgInfo['pid']">selected</if>>{$org.name}</option>
                    </foreach>
                </select>
            </div>
            <div class="form-group">
                <label for="recipient-name" class="control-label">简介:</label>
                <textarea class="form-control" rows="3" name="introduce">{$orgInfo.introduce}</textarea>
            </div>
            <div class="form-group">
                <label for="recipient-name" class="control-label">省市区/县:</label>
                <div>
                    <div class="col-sm-4">
                        <select name="province" id="province" class="form-control">
                            <foreach name="province" item="prov">
                                <option value="{$prov.id}" <if condition="$orgInfo['province'] eq $prov['id']">selected</if>>{$prov.name}</option>
                            </foreach>
                        </select>
                    </div>
                    <div class="col-sm-4">
                        <select class="form-control" name="city" id="city">

                        </select>
                    </div>
                    <div class="col-sm-4">
                        <select class="form-control" name="county" id="county">

                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="recipient-name" class="control-label">地址:</label>
                <input type="text" class="form-control" name="address" value="{$orgInfo.address}">
            </div>
        </form>
        <div class="modal-footer">
            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
            <button type="button" id="OrgSave" class="btn btn-primary">保存</button>
        </div>
    </div>
</div>
<script type="text/javascript">
    var city = "{$orgInfo.city}";
    var county = "{$orgInfo.county}";

    $(function () {
        $("#province").bind("change",chooseProvince);
        $("#city").bind("change",chooseCity);
        $("#province,#city").change();
    });

    function chooseProvince() {
        var pid = $(this).val();
        $("#city,#county").empty();
        $.ajax({
            url: "{:U('Admin/Org/getRegionByPid')}",
            type: "post",
            dataType: "json",
            data: {pid: pid},
            success: function (data) {
                var html = '';
                $.each(data,function (index,item) {
                    var selected = (city == item.id) ? " selected" : "";
                    html += '<option value="'+item.id+'"'+selected+'>'+item.name+'</option>';
                });
                $("#city").html(html).change();
            }
        });
    }

    function chooseCity() {
        var pid = $(this).val();
        $("#county").empty();
        $.ajax({
            url: "{:U('Admin/Org/getRegionByPid')}",
            type: "post",
            dataType: "json",
            data: {pid: pid},
            success: function (data) {
                var html = '';
                $.each(data,function (index,item) {
                    var selected = (county == item.id) ? " selected" : "";
                    html += '<option value="'+item.id+'"'+selected+'>'+item.name+'</option>';
                });
                $("#county").html(html);
            }
        });
    }

    $("#OrgSave").click(function(){
        common.ajax("{:U('Admin/Org/saveOrg')}",$("#modalForm").serialize(),function(){
            $("#commonModal").modal('toggle');
            //common.reload();
            loadTableList();
        });
    });
</script>